home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************\
-
- File: menus.c
-
- Purpose: This module handles menu selections.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program in a file named "GNU General Public License".
- If not, write to the Free Software Foundation, 675 Mass Ave,
- Cambridge, MA 02139, USA.
-
- \**********************************************************************/
-
- #include "graphics.h"
- #include "menus.h"
- #include "help.h"
- #include "environment.h"
- #include "sounds.h"
- #include "error.h"
- #include "launch.h"
- #include "file interface.h"
- #include "jotto load-save.h"
- #include "jotto.h"
- #include "jotto environment.h"
- #include "debinhex dispatch.h"
- #include "file management.h"
- #include "program globals.h"
-
- extern long menuDisable : 0x0b54;
-
- Boolean gMenuEnabled;
- MenuHandle gAppleMenu;
- MenuHandle gFileMenu;
- MenuHandle gEditMenu;
- MenuHandle gOptionsMenu;
- MenuHandle gFluffMenu;
- MenuHandle gGasketMenu;
-
- enum
- {
- appleMenu = 400, fileMenu, editMenu, optionsMenu, fluffMenu, gasketMenu,
-
- aboutItem = 1, aboutMSGItem, helpPointerItem,
-
- newItem = 1, openItem, closeItem, saveItem, saveAsItem, file_unused1, quitItem,
-
- undoItem = 1, edit_unused1, cutItem, copyItem, pasteItem, clearItem, edit_unused2,
- selectAllItem,
-
- useFiveLetter = 1, useSixLetter, options_unused1, dupToggle, nonWordsToggle,
- soundToggle, animationToggle, options_unused2, showNotePad, boardFrontItem,
-
- deBinHexItem = 1, launchItem, forceQuitItem, fluff_unused1, hideItem
- };
-
- /*-----------------------------------------------------------------------------------*/
- /* internal stuff for menus.c */
-
- void HandleAppleMenu(short menuItem);
- void HandleFileMenu(short menuItem);
- void HandleEditMenu(short menuItem);
- void HandleHelpMenu(void);
- void HandleOptionsMenu(short menuItem);
- void HandleFluffMenu(short menuItem);
-
- Boolean InitTheMenus(void)
- {
- Handle MBARHandle;
-
- if ((MBARHandle=GetNewMBar(400))==0L) /* sez which menus are in menu bar. */
- return FALSE;
- SetMenuBar(MBARHandle); /* set this to be THE menu bar to use. */
-
- if ((gAppleMenu=GetMHandle(appleMenu))==0L) /* GetNewMBar also got menu handles of */
- return FALSE;
- if ((gFileMenu=GetMHandle(fileMenu))==0L) /* every menu it includes, so just */
- return FALSE;
- if ((gEditMenu=GetMHandle(editMenu))==0L) /* grab these handles and assign them */
- return FALSE;
- if ((gOptionsMenu=GetMHandle(optionsMenu))==0L)
- return FALSE;
- if ((gFluffMenu=GetMHandle(fluffMenu))==0L)
- return FALSE;
- if ((gGasketMenu=GetMHandle(gasketMenu))==0L)
- return FALSE;
-
- if (gSystemSevenOrLater)
- {
- AppendMenu(gFluffMenu, "\p-");
- AppendMenu(gFluffMenu, "\pHide/1");
- }
-
- AddResMenu(gAppleMenu, 'DRVR'); /* adds control panels to apple menu */
-
- AdjustMenus(); /* dim/enable/check/mark menus/items */
- DrawMenuBar(); /* draws the actual menu bar */
-
- return TRUE;
- }
-
- void ShutDownTheMenus(void)
- {
- ReleaseResource(gAppleMenu);
- ReleaseResource(gFileMenu);
- ReleaseResource(gEditMenu);
- ReleaseResource(gOptionsMenu);
- ReleaseResource(gFluffMenu);
- ReleaseResource(gGasketMenu);
- }
-
- void AdjustMenus(void)
- {
- WindowPeek theWindow;
- short kind;
-
- if (gInProgress)
- {
- DisableItem(gAppleMenu, aboutItem);
- DisableItem(gAppleMenu, aboutMSGItem);
- DisableItem(gAppleMenu, helpPointerItem);
- DisableItem(gFileMenu, 0);
- if (gSystemSevenOrLater)
- {
- DisableItem(gFluffMenu, deBinHexItem);
- DisableItem(gFluffMenu, launchItem);
- DisableItem(gFluffMenu, hideItem);
- }
- else DisableItem(gFluffMenu, 0);
-
- DisableItem(gEditMenu, 0);
- DisableItem(gOptionsMenu, 0);
- DisableItem(gGasketMenu, 0);
- }
- else
- {
- EnableItem(gAppleMenu, aboutItem);
- EnableItem(gAppleMenu, aboutMSGItem);
- EnableItem(gAppleMenu, helpPointerItem);
- EnableItem(gFileMenu, 0);
- if (gSystemSevenOrLater)
- {
- EnableItem(gFluffMenu, deBinHexItem);
- EnableItem(gFluffMenu, launchItem);
- EnableItem(gFluffMenu, hideItem);
- }
- else EnableItem(gFluffMenu, 0);
-
- EnableItem(gEditMenu, 0);
- EnableItem(gOptionsMenu, 0);
- EnableItem(gGasketMenu, 0);
-
- theWindow = (WindowPeek)FrontWindow();
- kind = theWindow ? theWindow->windowKind : 0;
-
- if ((kind < 0) ||
- ((gTheWindow[kNotePad]!=0L) && (gTheWindow[kNotePad]==FrontWindow())))
- {
- if (kind<0)
- EnableItem(gEditMenu, undoItem);
- else
- DisableItem(gEditMenu, undoItem);
- EnableItem(gEditMenu, cutItem);
- EnableItem(gEditMenu, copyItem);
- EnableItem(gEditMenu, pasteItem);
- EnableItem(gEditMenu, clearItem);
- EnableItem(gEditMenu, selectAllItem);
- }
- else
- {
- DisableItem(gEditMenu, undoItem);
- DisableItem(gEditMenu, cutItem);
- DisableItem(gEditMenu, copyItem);
- DisableItem(gEditMenu, pasteItem);
- DisableItem(gEditMenu, clearItem);
- DisableItem(gEditMenu, selectAllItem);
- }
-
- if(theWindow)
- EnableItem(gFileMenu, closeItem);
- else
- DisableItem(gFileMenu, closeItem);
-
- if (FrontWindow()!=0L)
- {
- if ((gTheWindow[kMainWindow]!=0L) && (gTheWindow[kMainWindow]!=FrontWindow()))
- {
- SetItem(gOptionsMenu, boardFrontItem, "\pBring board to front");
- EnableItem(gOptionsMenu, boardFrontItem);
- }
- else if (gTheWindow[kNotePad]!=0L)
- {
- SetItem(gOptionsMenu, boardFrontItem, "\pBring note pad to front");
- if (gTheWindow[kNotePad]==FrontWindow())
- DisableItem(gOptionsMenu, boardFrontItem);
- else
- EnableItem(gOptionsMenu, boardFrontItem);
- }
- else
- {
- SetItem(gOptionsMenu, boardFrontItem, "\pBring board to front");
- DisableItem(gOptionsMenu, boardFrontItem);
- }
- }
- else
- {
- SetItem(gOptionsMenu, boardFrontItem, "\pBring board to front");
- DisableItem(gOptionsMenu, boardFrontItem);
- }
-
- if (gTheWindow[kMainWindow])
- {
- EnableItem(gFileMenu, saveItem);
- EnableItem(gFileMenu, saveAsItem);
- DisableItem(gOptionsMenu, dupToggle);
- DisableItem(gOptionsMenu, useFiveLetter);
- DisableItem(gOptionsMenu, useSixLetter);
- }
- else
- {
- DisableItem(gFileMenu, saveItem);
- DisableItem(gFileMenu, saveAsItem);
- EnableItem(gOptionsMenu, dupToggle);
- if (FiveLetterOKQQ())
- EnableItem(gOptionsMenu, useFiveLetter);
- else
- DisableItem(gOptionsMenu, useFiveLetter);
-
- if (SixLetterOKQQ())
- EnableItem(gOptionsMenu, useSixLetter);
- else
- DisableItem(gOptionsMenu, useSixLetter);
- }
-
- if (gSystemSevenOrLater)
- EnableItem(gFluffMenu, forceQuitItem);
- else
- DisableItem(gFluffMenu, forceQuitItem);
-
- if (gSoundAvailable)
- EnableItem(gOptionsMenu, soundToggle);
- else
- DisableItem(gOptionsMenu, soundToggle);
- }
- CheckItem(gOptionsMenu, dupToggle, gAllowDup);
- CheckItem(gOptionsMenu, nonWordsToggle, gNonWordsCount);
- CheckItem(gOptionsMenu, animationToggle, gAnimation);
- SetItemMark(gOptionsMenu, useFiveLetter, (gNumLetters==5) ? '◊' : noMark);
- SetItemMark(gOptionsMenu, useSixLetter, (gNumLetters==6) ? '◊' : noMark);
- CheckItem(gOptionsMenu, showNotePad, (gTheWindow[kNotePad]!=0L));
- CheckItem(gOptionsMenu, soundToggle, gSoundToggle&&gSoundAvailable);
- }
-
- void HandleMenu(long mSelect)
- {
- short menuID = HiWord(mSelect);
- short menuItem = LoWord(mSelect);
-
- if (menuID==0)
- {
- menuID=HiWord(menuDisable);
- menuItem=LoWord(menuDisable);
- gMenuEnabled=FALSE;
- }
- else gMenuEnabled=TRUE;
- menuDisable=0L;
-
- switch (menuID)
- {
- case appleMenu:
- HandleAppleMenu(menuItem);
- break;
- case fileMenu:
- HandleFileMenu(menuItem);
- break;
- case editMenu:
- HandleEditMenu(menuItem);
- break;
- case optionsMenu:
- HandleOptionsMenu(menuItem);
- break;
- case fluffMenu:
- HandleFluffMenu(menuItem);
- break;
- }
- }
-
- void DoTheCloseThing(WindowPeek theWindow)
- /* a standard close procedure, called when "close" is chosen from File menu and when
- a window is closed through its close box */
- {
- Boolean gotone;
- short i;
- short kind;
-
- if (theWindow==0L)
- return;
-
- kind = theWindow ? theWindow->windowKind : 0;
- if (kind<0) /* DA window or other system window */
- CloseDeskAcc(kind);
- else
- {
- gotone=FALSE;
- /* see if it's one of ours */
- for (i=0; (i<NUM_WINDOWS) && (!gotone); i++)
- gotone=((WindowPtr)theWindow==gTheWindow[i]);
-
- if (gotone) /* if it's one of ours... see graphics.c */
- CloseTheWindow(gTheWindowData[i-1]); /* this may return FALSE = not closed */
- else
- DisposeWindow((WindowPtr)theWindow); /* not one of ours, so just close it */
-
- AdjustMenus(); /* may affect which menu items or menus are available, etc */
- }
- }
-
- void HandleAppleMenu(short menuItem)
- {
- GrafPtr savePort;
- Str255 name;
-
- switch (menuItem)
- {
- case aboutItem:
- if (gMenuEnabled)
- {
- OpenTheWindow(kAbout);
- }
- else DoSound(sound_fluff, TRUE);
- break;
- case aboutMSGItem:
- if (gMenuEnabled)
- OpenTheWindow(kAboutMSG);
- else DoSound(sound_fluff, TRUE);
- break;
- case helpPointerItem:
- if (gMenuEnabled)
- HandleHelpMenu();
- else DoSound(sound_fluff, TRUE);
- break;
- default:
- if (menuItem > helpPointerItem+1)
- {
- GetPort(&savePort);
- GetItem(gAppleMenu, menuItem, name);
- OpenDeskAcc(name);
- SetPort(savePort);
- }
- break;
- }
- }
-
- void HandleFileMenu(short menuItem)
- {
- WindowPtr theWindow;
- short i;
- Boolean gotone;
-
- switch (menuItem)
- {
- case newItem:
- if (gMenuEnabled)
- NewGame();
- else DoSound(sound_fluff, TRUE);
- break;
- case openItem:
- if (gMenuEnabled)
- LoadSaveDispatch(TRUE, FALSE);
- else DoSound(sound_fluff, TRUE);
- break;
- case closeItem:
- if (gMenuEnabled)
- DoTheCloseThing((WindowPeek)FrontWindow());
- else DoSound(sound_fluff, TRUE);
- break;
- case saveItem:
- if (gMenuEnabled)
- LoadSaveDispatch(FALSE, TRUE);
- else DoSound(sound_fluff, TRUE);
- break;
- case saveAsItem:
- if (gMenuEnabled)
- LoadSaveDispatch(FALSE, FALSE);
- else DoSound(sound_fluff, TRUE);
- break;
- case quitItem:
- if (gMenuEnabled)
- gDone = TRUE;
- else DoSound(sound_fluff, TRUE);
- break;
- }
- }
-
- void HandleEditMenu(short menuItem)
- {
- ExtendedWindowDataHandle theData;
-
- if ((menuItem==0) || (menuItem==2) || (menuItem>CountMItems(gEditMenu)))
- return;
-
- if (gMenuEnabled)
- {
- if (gFrontWindowIsOurs)
- {
- theData=(ExtendedWindowDataHandle)GetWRefCon(FrontWindow());
- switch (menuItem)
- {
- case undoItem:
- ((**theData).dispatchProc)((WindowDataHandle)theData, kUndo, 0L);
- break;
- case cutItem:
- ((**theData).dispatchProc)((WindowDataHandle)theData, kCut, 0L);
- break;
- case copyItem:
- ((**theData).dispatchProc)((WindowDataHandle)theData, kCopy, 0L);
- break;
- case pasteItem:
- ((**theData).dispatchProc)((WindowDataHandle)theData, kPaste, 0L);
- break;
- case clearItem:
- ((**theData).dispatchProc)((WindowDataHandle)theData, kClear, 0L);
- break;
- case selectAllItem:
- ((**theData).dispatchProc)((WindowDataHandle)theData, kSelectAll, 0L);
- break;
- }
- }
- else SystemEdit(menuItem - 1);
- }
- else DoSound(sound_fluff, TRUE);
- }
-
- void HandleOptionsMenu(short menuItem)
- {
- WindowPtr theWindow;
-
- switch (menuItem)
- {
- case dupToggle:
- case nonWordsToggle:
- case useFiveLetter:
- case useSixLetter:
- case animationToggle:
- case soundToggle:
- if (gMenuEnabled)
- {
- switch (menuItem)
- {
- case dupToggle: gAllowDup=!gAllowDup; break;
- case nonWordsToggle: gNonWordsCount=!gNonWordsCount; break;
- case useFiveLetter: gNumLetters=0x05; break;
- case useSixLetter: gNumLetters=0x06; break;
- case animationToggle: gAnimation=!gAnimation; break;
- case soundToggle: gSoundToggle=!gSoundToggle; DoSound(sound_on, TRUE); break;
- }
- }
- else DoSound(sound_fluff, TRUE);
- break;
- case showNotePad:
- if (gMenuEnabled)
- {
- if (gTheWindow[kNotePad])
- {
- SelectWindow(gTheWindow[kNotePad]);
- CloseTheWindow(gTheWindowData[kNotePad]);
- }
- else
- {
- OpenTheWindow(kNotePad);
- }
- }
- else DoSound(sound_fluff, TRUE);
- break;
- case boardFrontItem:
- if (FrontWindow()!=0L)
- {
- if ((gTheWindow[kMainWindow]!=0L) && (gTheWindow[kMainWindow]!=FrontWindow()))
- {
- SelectWindow(gTheWindow[kMainWindow]);
- }
- else if (gTheWindow[kNotePad]!=0L)
- {
- SelectWindow(gTheWindow[kNotePad]);
- }
- else DoSound(sound_fluff, TRUE);
- }
- else DoSound(sound_fluff, TRUE);
- }
- }
-
- void HandleHelpMenu(void)
- {
- OpenTheWindow(kHelp);
- }
-
- void HandleFluffMenu(short menuItem)
- {
- switch (menuItem)
- {
- case deBinHexItem:
- if (gMenuEnabled)
- {
- if (GetSourceFile(&inputFS, TRUE, FALSE))
- HandleError(DeBinHexDispatch(), FALSE);
- }
- else DoSound(sound_fluff, TRUE);
- break;
- case launchItem:
- if (gMenuEnabled)
- {
- LaunchDispatch();
- }
- else DoSound(sound_fluff, TRUE);
- case forceQuitItem:
- if (gMenuEnabled)
- SysError(0x4e22);
- else DoSound(sound_fluff, TRUE);
- break;
- case hideItem:
- if (gMenuEnabled)
- {
- MenuKey(0);
- }
- else DoSound(sound_fluff, TRUE);
- break;
- }
- }
-